package com.yojcodesendbox.controller;

import com.yojcodesendbox.codesendbox.CodeSandbox;
import com.yojcodesendbox.codesendbox.factory.ExecuteCodeSendBoxFactory;
import com.yojcodesendbox.model.ExecuteCodeRequest;
import com.yojcodesendbox.model.ExecuteCodeResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/codeSendbox")
public class MainController {


    @Autowired
    ExecuteCodeSendBoxFactory executeCodeSendBoxFactory;

    @PostMapping("/execute")
    public ExecuteCodeResponse executeCode(@RequestBody ExecuteCodeRequest executeCodeRq) {
        String language = executeCodeRq.getLanguage();
        CodeSandbox codeSandbox = executeCodeSendBoxFactory.getCodeSandbox(language);
        return codeSandbox.executeCode(executeCodeRq);
    }
}
